package dao

import (
	"Management/common"
	"Management/model"
)

//查询登陆账号
func QueryLoginer(phone string)(loginer model.Loginer){
	db:=common.InitDB()
	db.Where("phone =?",phone).First(&loginer)
	return loginer
}
//添加登录账号
func AddLoginer(phone string)(err error){
	db:=common.InitDB()
	loginer:=model.Loginer{
		Phone: phone,
		Password: "000000",
	}
	err=db.Create(&loginer).Error
	return err
}
//删除登录账号
func DeleteLoginer(phone string)(err error){
	db:=common.InitDB()
	var loginer model.Loginer
	err=db.Where("phone =?",phone).Delete(&loginer).Error
	return err
}
//修改密码
func ChangeLoginerPassword(phone string,password string)(err error){
	db:=common.InitDB()
	var loginer model.Loginer
	err=db.Where("phone =?",phone).First(&loginer).Update("password",password).Error
	return err
}
//修改账号
func ChangeLoginerPhone(phone string,newphone string)(err error){
	db:=common.InitDB()
	var loginer model.Loginer
	err=db.Where("phone =?",phone).First(&loginer).Update("phone",newphone).Error
	return err
}